package com.cooldatasoft.support.git;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * User: brano
 */
abstract class AbstractFileNode implements FileNodeInterface {
    private Date dateLastModify;
    private String fileName;

    protected AbstractFileNode(long lastModified, String fileName) {
        this.dateLastModify = new Date(lastModified);
        this.fileName = fileName;
    }

    @Override
    public Date lastModified() {
        return dateLastModify;
    }

    @Override
    public String getName() {
        return fileName;
    }

    @Override
    public String getFullInfo() {
        String dateOut;
        DateFormat dateFormatter;

        dateFormatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault());
        dateOut = dateFormatter.format(dateLastModify);

        return "\n" + fileName  + "\t"
                + (isDirectory() ? " DIR" : "   ") + "\t"
                + dateOut + "\t"
                + (this instanceof FileNode ?
                    " size: " + ((FileNode) this).getSize() + " KB" : "");
    }

    @Override
    public String toString() {
        return fileName;
    }
}
